{include file='./inc/header.tpl'}
<div id="wrap">
    {include file='./inc/head.tpl'}
    <div id="contents">
        <div class="ttl">
            <h2>求人登録</h2>
        </div>
        <form action="./" method="post" name="search_form">
            <input type="hidden" name="mode" value="search" />
            <input type="hidden" name="transid" value="{$transactionid}">
            <!--{foreach from=$arrHidden key="key" item="item"}-->
                <!--{if is_array($item)}-->
                    <!--{foreach item=c_item from=$item}-->
                        <input type="hidden" name="{$key}[]" value="{$c_item}" />
                    <!--{/foreach}-->
                <!--{else}-->
                    <input type="hidden" name="{$key}" value="{$item}" />
                 <!--{/if}-->
            <!--{/foreach}-->
        </form>
        <div class="formBox">
            <h3>情報入力</h3>
            {include file='./inc/message.tpl'}
            <form action="./admin/job_edit" method="post" enctype="multipart/form-data" name="form1" id="form1">
                <input type="hidden" name="transid" value="{$transactionid}">
                <input type="hidden" name="mode" value="" />
                {assign var=key value="job_id"}
                <input type="hidden" name="{$key}" value="{$arrForm[$key].value}" />
            <!--{foreach from=$arrHidden key="key" item="item"}-->
                <!--{if is_array($item)}-->
                    <!--{foreach item=c_item from=$item}-->
                        <input type="hidden" name="{$key}[]" value="{$c_item}" />
                    <!--{/foreach}-->
                <!--{else}-->
                    <input type="hidden" name="{$key}" value="{$item}" />
                 <!--{/if}-->
            <!--{/foreach}-->
                <dl>
                    <dt>
                        仕事コード
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="job_code"}
                    <dd>
                        <input name="{$key}" value="{$arrForm[$key].value}">
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        タイトル
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="content_title"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        業種
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="content_industry"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>カテゴリ</dt>
                    <dd>
                        {assign var=key value="category_id"}
                        {html_options class="selectField" name=$key options=$config.default_all+$category selected=$arrForm[$key].value}
                        {if !empty($arrErr[$key].error)}
                            <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>フィールド</dt>
                    <dd>
                        {assign var=key value="field_id"}
                        {assign var=field_id value=$arrForm[$key].value}
                        <input type="button" class="checkAll" value="全てチェック">
                        <input type="button" class="uncheckAll" value="全てチェック解除">
                        <br>
                        <div id="field">
                            {foreach from=$field key="index" item="item"}
                                <input type="checkbox" class="{$key}" name="field_id[]" value="{$index}" {if $index|in_array:$field_id}checked{/if}>{$item}
                            {/foreach}
                        </div>
                    </dd>
                    <dt>
                        職種
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="content_category"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        給与
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="salary"}
                    <dd>
                        <input type="text" name="{$key}" style="width: 100px;" size="15" value="{$arrForm[$key].value}" />
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        給与内容
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="content_salary"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        地域
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="pref_id"}
                    <dd>{html_options name=$key options=$config.pref selected=$arrForm[$key].value}</dd>
                    <dt>
                        勤務地
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="content_location"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>経験</dt>
                    <dd>
                        {assign var=key value="experience"}
                        <input type="text" name="{$key}" value="{$arrForm[$key].value}" size="10" />
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        必要な日本語力
                    </dt>
                    {assign var=key value="content_jp_skill"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        必要な英語力
                    </dt>
                    {assign var=key value="content_en_skill"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        資格その他必要条件
                    </dt>
                    {assign var=key value="content_require"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        雇用期間
                    </dt>
                    {assign var=key value="content_contract"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        会社の従業員数
                    </dt>
                    {assign var=key value="content_company_size"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        外国人を採用したことの有無
                    </dt>
                    {assign var=key value="content_status_adopt"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        その他公開条件
                    </dt>
                    {assign var=key value="content_others"}
                    <dd>
                        <textarea name="{$key}" cols="60" rows="6">{$arrForm[$key].value}</textarea>
                        {if !empty($arrErr[$key].error)}
                        <div class="attention">{$arrErr[$key].error}</div>
                        {/if}
                    </dd>
                    <dt>
                        求人状態
                        <span class="require">※</span>
                    </dt>
                    {assign var=key value="status"}
                    <dd>{html_options name=$key options=$config.job_status selected=$arrForm[$key].value}</dd>
                    
                    <dt>ロゴ<span class="require">※</span></dt>
                    {assign var=key value="logo"}
                    {assign var=key1 value="save_logo"}
                    <dd>
                        <div>
                            <input type="file" name="{$key}" onchange="readURL(this);"/><br>
                            {if !empty($arrErr[$key].error)}<div class="{$key} attention">{$arrErr[$key].error}</div>{/if}
                            {if $arrForm[$key1].value != ''}
                            <img id="{$key}" src="/photo{if !empty($upload_flg[$key])}_tmp{/if}/{$arrForm[$key1].value}" width="160px" height="160px"/>
                            <input type="hidden" name="{$key}" value="{$arrForm[$key].value}">
                            <input type="hidden" name="{$key1}" value="{$arrForm[$key1].value}">
                            {else}
                            <img id="{$key}" src="#" width="160px" height="160px" style="display: none;" />
                            {/if}
                        </div>
                    </dd>
                    {for $i=1 to 3}
                    <dt>画像{$i}</dt>
                    {assign var=key value="sub_image`$i`"}
                    {assign var=key1 value="save_sub_image`$i`"}
                    <dd>
                        <div>
                            <input type="file" name="{$key}" onchange="readURL(this);"/><br>
                            {if !empty($arrErr[$key].error)}<div class="{$key} attention">{$arrErr[$key].error}</div>{/if}
                            {if $arrForm[$key1].value != ''}
                            <img id="{$key}" src="/photo{if !empty($upload_flg[$key])}_tmp{/if}/{$arrForm[$key1].value}" width="160px" height="160px"/>
                            <input type="hidden" name="{$key}" value="{$arrForm[$key].value}">
                            <input type="hidden" name="{$key1}" value="{$arrForm[$key1].value}">
                            {else}
                            <img id="{$key}" src="#" width="160px" height="160px" style="display: none;" />
                            {/if}
                        </div>
                    </dd>
                    {/for}
                    <dt>掲載日<span class="require">※</span></dt>
                    <dd>
                        <span id="registDate">
                            {assign var=key value="regist_datetime"}
                            <input class="datepicker" type="text" readonly='true' name="{$key}" value="{$arrForm[$key].value|date_format:'%Y/%m/%d'}" size="10" />
                            {if !empty($arrErr[$key].error)}
                            <div class="attention">{$arrErr[$key].error}</div>
                            {/if}
                        </span>
                    </dd>
                </dl>
                <input class="primary" onclick="fnReturn();" type="button" value="検索画面に戻る" />
                <input class="primary" onclick="submitForm('form1','complete');" type="button" value="この内容で登録する" />
            </form>
        </div>
        <!-- #fromBox -->
    </div>
    <!-- #contents -->
</div>
<!-- #wrap -->
<script type="text/javascript">
$(document).ready(function($) {

	$('.datepicker').datepicker({ dateFormat: "yy/mm/dd" });
    $(".specify").change(function() {
        var specify = 1;
        var tmp = $(this).attr("class").split(" ");
        $("#" + tmp[1]).css("display", ($(this).val() == specify ? "" : "none"));
    });

    $(".checkAll").click(function() {
        $(".field_id").prop('checked', true);
    });

    $(".uncheckAll").click(function() {
        $(".field_id").prop('checked', false);
    });

    $(".selectField").change(function() {
        var category_id = $(this).val();
        $("#field").empty();
        $.ajax({
            url: "/selectField",
            method: "GET",
            async: false,
            data: ({ id : category_id }),
            dataType: 'json',
            success: function(data) {
                if(data != 'NG') {
                    var htmlStr = '';
                    $.each(data, function(k, v){
                        htmlStr += '<input type="checkbox" class="field_id" name="field_id[]" value="'+v.field_id+'">'+v.field_name
                    });
                    $("#field").append(htmlStr);
                }
            }
        });
    });
});

function readURL(input) {
    var fileTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp'];
    if (input.files && input.files[0]) {
        $("."+ input.name).hide();
        var extension = input.files[0].name.split('.').pop().toLowerCase(),
        isSuccess = fileTypes.indexOf(extension) > -1;
        
        if (isSuccess) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $("#"+ input.name).attr('src', e.target.result);
                $("#"+ input.name).show();
            }
            reader.readAsDataURL(input.files[0]);
        } else {
            $("#"+ input.name).hide();
        }
    }
}

function fnReturn() {
    document.search_form.action = './admin/job';
    document.search_form.mode.value = "search";
    document.search_form.submit();
    return false;
}
</script>
{include file='./inc/footer.tpl'}
